﻿package shooter {
	import flash.display.BitmapData;
	import flash.geom.Vector3D;
	import render3d.CrossEngineObject3D;
	import render3d.interfaces.IRender3DAdapter;
	import render3d.interfaces.IRender3DForObject3D;

	public class Bullet extends CrossEngineObject3D
	{
		[Embed(source = '../../assets/fireball.png')] private static const FIREBALL_CLASS:Class;
		static private const FIREBALL_BITMAP_DATA:BitmapData = new FIREBALL_CLASS().bitmapData;
		
		public var boundingRadius:Number
		
		public function Bullet( render:IRender3DAdapter, radius:int ):void 
		{
			super(IRender3DForObject3D(render))
			boundingRadius = radius * 3;
			_object3D = render.createSprite3D(FIREBALL_BITMAP_DATA).object3D;
		}
		
		public function hitTestObject2( monster:Monster, multiplier:Number = 1 ):Boolean
		{
			var monsterPosition:Vector3D = monster.getPosition();
			var dx:Number = this.matrix.position.x - monsterPosition.x;
			var dy:Number = this.matrix.position.y - monsterPosition.y;
			var dz:Number = this.matrix.position.z - monsterPosition.z;
			var d2:Number = dx*dx + dy*dy + dz*dz;
			var sA:Number = this ? this.boundingRadius : 0;
			var sB:Number = monster ?  monster.boundingRadius : 0;
			sA = sA * multiplier;
			return sA + sB > d2;
		}
		
		public function destroy():void 
		{
			IRender3DAdapter(render).removeChild(this);
		}
	}
}